'''
数据库测试
'''
# from orm import Request, Status, Log
# # print(Request.select(Request.slave_id).distinct())
# # a = Request.select(Request.slave_id)
# # a_lt = list(a)
# # slave = Status.select().where(Status.speed!=0)
# # # print(slave.count())
# # print(list(slave))
# # for status in slave:
# #     print(status.amount)
# # print(Status.select().where(Status.speed!=0).count())
# a = Status.get(Status.speed!=0)
# print(a.__data__)
# '''
# url_for 
# '''
# from flask import Flask,url_for,redirect
# from route import monitor
# app = Flask(__name__)
# app.register_blueprint(monitor, url_prefix='/monitor')
# @app.route('/<id>')
# def redi(id):
#     print("原页面逻辑")
#     url = url_for('monitor.test',id=id)
#     return redirect(url)

# if __name__ == "__main__":
#     app.run(port=45575)


# from route import slave

# slave.get_slave(1)

# from orm import Status
# # print(Status.get(Status.id==1).__data__)
# # for data in Status.select().where((Status.open==1) & (Status.speed==0)):
# #     print(data.id,end=' ')
# from orm import Log
# import datetime
# from settings import FeeRate
# import numpy as np 


# re_data = []
# datafi = []
# # 读取数据
# for i,data in enumerate(Log.select().where((Log.slave_id==1)&(Log.res_time!=None))):
#     # re_data.append({'id':i,'slave_id':data.slave_id,'req_time':None,})
#     re_data.append({'slave_id':data.slave_id,'speed':data.speed,'res_time':data.res_time})

# # 删除改变温度重复的log
# for k in range(len(re_data)):
#     try:
#         if re_data[k]['speed']==re_data[k+1]['speed']:
#             re_data.pop(k+1)
#     except:
#         break        
# # 计算一次开关记得详单
# j=0
# while j<len(re_data):
#     try:
#         datafi.append({'slave_id':re_data[j]['slave_id'],'res_start':re_data[j]['res_time'],'res_end':re_data[j+1]['res_time'],'res_time':(re_data[j+1]['res_time']-re_data[j]['res_time']).seconds,'speed':re_data[j]['speed']})
#         if re_data[j]['speed']!=0 and re_data[j+1]['speed']!=0:
#             j+=1
#             pass
#         else:
#             j+=2

#     except:
#         break

# # 计算费用
# def Cost(res_time,speed,feerate):
#     cost = 0.0
#     if speed == 1:
#         cost = (res_time / 60) / 3 * FeeRate
#     elif speed == 2:
#         cost = (res_time / 60) / 2 * FeeRate
#     elif speed == 3:
#         cost = (res_time / 60) * 1 * FeeRate
#     return cost

# # 加入计算的费用
# for num,log in enumerate(datafi):
#     log['id'] = num
#     log['feedrate'] = FeeRate
#     log['cur_fee'] = Cost(log['res_time'],log['speed'],FeeRate)

# subtotal = np.cumsum(np.array([part['cur_fee'] for part in datafi]))
# # 加入请求时间和费用
# for num,q_time in enumerate(Log.select().where((Log.slave_id==1)&(Log.req_time!=None))):
#     datafi[num]['req_time'] = q_time.req_time 
#     datafi[num]['subtotal'] = float(subtotal[num])


# for i in datafi:    
#     print(i)
# from orm import Room
# import time
# a =time.strftime('%Y-%m-%d %H:%M:%S')
# print(a)
# Room.insert({'id':2,'open_time':a}).execute()
# print(Room.get(Room.id==1))

# from orm import Status 
# is_open = Status.select().where(Status.open!=0).count()
# from route import log
# from flask import Flask

# app = Flask(__name__)
# with app.app_context():
#     for id in range(1,6):
#         print(log.generate_bill(id))
    
#     # for i in log.generate_detail_oder(id):
#     #     print(i)
from orm import Status,Request
from peewee import fn
# try:
#     max_salary = Request.select(fn.Max(Request.speed)).scalar()
#     run_slave = Status.select().where(Status.speed!=0)
#     for status in run_slave:
#         print(int(status.speed)< max_salary)
# except Exception as e:
#     print(e)
# print(max_salary)
# Request.update({Request.speed:0}).where(Request.slave_id==2).execute()
speed_1 = Status.select().where(Status.speed==1)
for status in speed_1:
    print(status)
print('执行')